import { APP_DATE } from "./macro.mjs";

export class BuildInfo {
    target = "";
    build = false;
    mod = false;
    compress = false;
};

export class BuildConfig {
    title = "主页"; //页面标题
    content_version = "{{DATE}}"; //游戏中的左上角文字 {{DATE}}游戏发布时间，如果为空则会不显示
    hasEruda = false;
    gamePath = "games";
    bundlePath = "bundles";
    index_replace_content = {}; //key-value 解析成 ReplaceContent，key 作为 indexStr

    assemblerHeadContent() {
        let inHeadContent = ``;
        if (this.content_version) {
            inHeadContent += `<script type="text/javascript">window.SHOW_APP_DATE = true; window.APP_DATE="${this.content_version.replace("{{DATE}}", APP_DATE)}";</script>`;
        }
        else {
            inHeadContent += `<script type="text/javascript">window.SHOW_APP_DATE = false;window.APP_DATE="";</script>`;
        }

        if (this.hasEruda) {
            inHeadContent += `<script src="js/eruda.min.js"></script><script>if(typeof eruda !== 'undefined')eruda.init();</script>`;
        }
        return inHeadContent;
    }
};

export class ReplaceContent {
    indexStr = "";
    content = "";
    constructor(indexStr, content) {
        this.indexStr = indexStr;
        this.content = content;
    }
    replace(str) {
        let index = this.indexStr.replace("*", "");
        let content = this.indexStr.replace("*", this.content);
        return str.replace(index, content);
    }
};